const { shell } = require('electron');
const { dialog } = require('electron');
// 创建菜单模板
module.exports = {
  // process.platform 是 Node.js 提供的一个全局变量 'darwin'：表示 macOS 系统 'win32'：表示 Windows 系统 'linux'：表示 Linux 系统
  template: [
    {
      label: '文件',
      submenu: [
        {
          label: '打开', accelerator: 'Ctrl+O',
          click () {
            console.log("open")
          }
        },
        { label: '保存' },
        { type: 'separator' },
        { label: '退出', role: 'quit' }
      ]
    },
    {
      label: '编辑',
      submenu: [
        { label: '撤销', role: 'undo' },
        { label: '重做', role: 'redo' },
        { type: 'separator' },
        { label: '剪切', role: 'cut', accelerator: 'CmdOrCtrl+X', },
        { label: '复制', role: 'copy' },
        { label: '粘贴', role: 'paste' },
        { label: '删除', role: 'delete' },
        { type: 'separator' },
        { label: '全选', role: 'selectAll' }
      ]
    },
    {
      label: '查看',
      submenu: [{
        label: '重载',
        accelerator: (function () {
          if (process.platform === 'darwin') {
            return 'Ctrl+Command+A'
          } else {
            return 'F5'
          }
        })(),
        click: function (item, focusedWindow) {
          // if (focusedWindow) {
          //   // 重载之后, 刷新并关闭所有的次要窗体
          //   if (focusedWindow.id === 1) {
          //     BrowserWindow.getAllWindows().forEach(function (win) {
          //       if (win.id > 1) {
          //         win.close()
          //       }
          //     })
          //   }
            focusedWindow.reload()
          // }
        }
      }, {
        label: '切换开发者工具',
        accelerator: (function () {
          // 判断是否是macOS系统
          if (process.platform === 'darwin') {
            return 'Alt+Command+I'
          } else {
            return 'Ctrl+Shift+I'
          }
        })(),
        click: function (item, focusedWindow) {
          if (focusedWindow) {
            focusedWindow.toggleDevTools()
          }
        }
      }, {
        type: 'separator'
      }, {
        label: '应用程序菜单演示',
        click: function (item, focusedWindow) {
          if (focusedWindow) {
            const options = {
              type: 'info',
              title: '应用程序菜单演示',
              buttons: ['好的'],
              message: '此演示用于 "菜单" 部分, 展示如何在应用程序菜单中创建可点击的菜单项.'
            }
            dialog.showMessageBox(focusedWindow, options, function () { })
          }
        }
      }]
    },
    {
      label: '窗口',
      role: 'window',
      submenu: [{
        label: '最小化',
        accelerator: 'CmdOrCtrl+M',
        role: 'minimize'
      }, {
        label: '关闭',
        accelerator: 'CmdOrCtrl+W',
        role: 'close'
      }, {
        type: 'separator'
      }, {
        label: '重新打开窗口',
        accelerator: 'CmdOrCtrl+Shift+T',
        enabled: false, // 是否禁用  false 禁用 true
        key: 'reopenMenuItem',
        click: function () {
          app.emit('activate')
        }
      }]
    },
    {
      label: '帮助',
      submenu: [
        {
          label: '关于', click: function () {
            dialog.showMessageBox({
                title: '消息',
                message: '智能装备存储系统xxx',
              });
            // alert('Submenu: When clicked, the  option opens a web browser to the Electron official website.')
            //shell.openExternal('http://electron.atom.io')
            //return('Submenu: When clicked, the  option opens a web browser to the Electron official website.')
          }
        }
      ]
    }
  ],
}
